package com.sdkj.controller;


import com.sdkj.pojo.Checkitem;
import com.sdkj.service.CheckitemService;
import com.sdkj.util.MessageConstant;
import com.sdkj.util.PageResult;
import com.sdkj.util.QueryPageBean;
import com.sdkj.util.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.xml.ws.handler.MessageContext;
import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckController {
    @Resource
    private CheckitemService checkitemService;

    @PostMapping("/addItemInfo")
    public Result addItemInfo(@RequestBody Checkitem checkitem){
        boolean flag=checkitemService.addItemInfo(checkitem);
        if(flag){
            return new Result(flag, MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }else{
            return  new Result(flag,MessageConstant.ADD_CHECKITEM_FAIL);
        }
    }
    @PostMapping("/findPageInfo")
    public PageResult findPageInfo(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = checkitemService.findPageInfo(queryPageBean);
        return  pageResult;
    }
    @RequestMapping("/deleteInfoById")
    public Result deleteInfoById(Integer id){
        boolean flag = checkitemService.deleteInfoById(id);
        if (flag){
            return  new Result(flag,MessageConstant.DELETE_CHECKITEM_SUCCESS);
        }else{
            return  new Result(flag,MessageConstant.DELETE_CHECKITEM_FAIL);
        }
    }
    //回显编辑的数据
    @RequestMapping("/getItemInfoById")
    public Result getItemInfoById(Integer id){
        Checkitem checkitem = checkitemService.getItemInfoById(id);
        return new Result(true,"",checkitem);
    }

    //查询表中所有数据
    @RequestMapping("/getAllItemInfo")
    public Result getAllItemInfo(){
        List <Checkitem> list =checkitemService.getAllItemInfo();
        return new Result(true,null,list);
    }

    //


}
